package com.sumainfor.wx.tenant.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sumainfor.common.util.FieldCheckUtil;
import com.sumainfor.common.util.JsonResult;
import com.sumainfor.wx.tenant.service.IndexService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @Author Jack Chen
 * @Create 2019-02-22 15:13
 */
@RestController
@RequestMapping("/index")
public class IndexController {

    @Autowired
    private IndexService indexService;

    /**
     * 获得首页Banner
     *
     * @return
     */
    @RequestMapping("/getIndexBannerList")
    public JsonResult getIndexBannerList() {
        JsonResult res = indexService.getIndexBannerList();
        return res;
    }

    /**
     * 获得首页热门房源信息
     *
     * @return
     */
    @RequestMapping("/getHotHousingIndexData")
    public JsonResult getHotHousingIndexData(Page page) {
        return indexService.getHotHousingIndexData(page);
    }

    /**
     * 获得所有的热门房源信息数据
     *
     * @param page
     * @return
     */
    @RequestMapping("/getHotHousingAll")
    public JsonResult getHotHousingAll(Page page) {
        return indexService.getHotHousingAll(page);
    }

    /**
     * 获得租房攻略
     *
     * @param page
     * @return
     */
    @RequestMapping("/getRaidersMainList")
    public JsonResult getRaidersMainList(Page page) {
        return indexService.getRaidersMainList(page);
    }

    /**
     * 根据租房攻略主编号查询所有的内部房源
     *
     * @param page
     * @param raId
     * @return
     */
    @RequestMapping("/getRaidersInfoDataByRaId")
    public JsonResult getRaidersInfoDataByRaId(Page page, String raId) {
        System.out.println("接受的参数"+raId);
        if (StringUtils.isBlank(raId)) {
            return JsonResult.errorForEmpty();
        }
        return indexService.getRaidersInfoDataByRaId(page, raId);
    }

    /**
     * 功能描述:
     * 获取首页活动
     *
     * @Author zhlu
     * @Description //TODO
     * @Date 2019/3/10 14:38
     */
    @GetMapping("/getMovableList")
    public JsonResult getMovableList() {
        return indexService.getMovableList();
    }

    /**
     * 功能描述:
     * 根据编号获取首页活动详情
     *
     * @Author zhlu
     * @Description //TODO
     * @Date 2019/3/10 15:26
     */
    @GetMapping("/getMovableMap")
    public JsonResult getMovableMap(@RequestParam Map<String, Object> params) {
        JsonResult result = new JsonResult();
        if (!FieldCheckUtil.isMapFieldNotNull(params, new String[]{"MovId"})) {
            result.putFailed("MovId不能为空！");
            return result;
        }
        result = indexService.getMovableMap(params);
        return result;
    }

    /**
     * 功能描述:
     * 根据活动编号获取活动和房源中间表
     *
     * @Author zhlu
     * @Description //TODO
     * @Date 2019/3/12 18:22
     */
    @GetMapping("/getMovableHousingList")
    public JsonResult getMovableHousingList(@RequestParam Map<String, Object> params, Page page) {
        JsonResult result = new JsonResult();
        if (!FieldCheckUtil.isMapFieldNotNull(params, new String[]{"MovId"})) {
            result.putFailed("MovId不能为空！");
            return result;
        }
        result.put(indexService.getMovableHousingList(page, params));
        return result;
    }

}
